/**
 * 计算帖子发布距现在时间
 * @param {number} time
 * @returns {String}
 *
 */
export const formatTime = time => {
  const interval = Math.floor(Date.now() / 1000) - time;
  let str = "";
  const num = Math.floor(interval / 60);
  switch (true) {
    case num < 60:
      if (num === 0 || num < 0) {
        str = "刚刚";
      } else {
        str = num + "分钟前";
      }
      break;
    case num < 1440:
      str = Math.floor(num / 60) + "小时前";
      break;
    case num < 43200:
      str = Math.floor(num / 1440) + "天前";
      break;
    case num < 518400:
      str = Math.floor(num / 43200) + "月前";
      break;
    default:
      break;
  }
  return str;
};
